package com.google.code.p.restrpc.core.url;

import com.google.code.p.restrpc.RestfulRequest;
import com.google.code.p.restrpc.RpcProtocal;
import com.google.code.p.restrpc.ServiceNode;

/**
 * @author dz
 */
public class DefaultRestfulRequest extends AbstractRpcRequest implements
                                                             RestfulRequest {
    
    private Class resultType;
    
    /**
     * @return
     */
    public Class getResultType() {
        return resultType;
    }
    
    /**
     * @param resultType
     */
    public void setResultType(Class resultType) {
        this.resultType = resultType;
    }
    
    /**
     * 
     */
    public RpcProtocal getProtocal() {
        return RpcProtocal.HTTP;
    }
    
    /**
     * @param destination
     * @return
     */
    public String getRestfulUrl(ServiceNode destination) {
        StringBuilder sb = new StringBuilder(getProtocal().prefix()).append(destination.getAddress());
        if (destination.getPort() != 80) {
            sb.append(":").append(destination.getPort());
        }
        return sb.append(getContext())
                 .append(getServiceName())
                 .append("#")
                 .append(getMethodName())
                 .toString();
    }
    
}
